package dm71.espil;

import dm71.espil.PendingRequestsAdapter.PendingRequestHolder;
import dm71.espil.models.PendingRequest;
import dm71.espil.models.User;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * TODO Put here a description of what this class does.
 *
 * @author Moulde.
 *         Created Dec 22, 2011.
 */
public class FriendsListAdaptor extends ArrayAdapter<User>
{
	Context context;
	int layoutResourceID;
	User[] data = null;
	
	public FriendsListAdaptor(Context context, int layoutResourceID, User[] data)
	{
		super(context, layoutResourceID, data);
		this.layoutResourceID = layoutResourceID;
		this.context = context;
		this.data = data;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View row = convertView;
		FriendHolder holder = null;
		
		if(row == null)
		{
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
			row = inflater.inflate(layoutResourceID, null);
			
			holder = new FriendHolder();
			holder.txtFriendName = (TextView)row.findViewById(R.id.txtFriendName);
			row.setTag(holder);
		}
		else
		{
			holder = (FriendHolder)row.getTag();
		}
		
		User user = data[position];
		holder.txtFriendName.setText(user.getName() + " " + user.getLastName());
		
		return row;
	}
	
	static class FriendHolder
	{
		TextView txtFriendName;
	}
}
